package com.sikan.dragdemo

import android.annotation.SuppressLint
import android.content.ContentResolver
import android.content.ContentUris
import android.content.Context
import android.content.Intent
import android.database.Cursor
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.os.FileUtils
import android.provider.DocumentsContract
import android.provider.MediaStore
import android.provider.OpenableColumns
import android.text.TextUtils
import android.util.Log
import androidx.core.content.FileProvider
import java.io.*
import java.util.*

/**
 * Created by jeremylau on 2022/9/7.
 */
class FileUtils {

    companion object {

        /**
         * 根据Uri获取文件绝对路径，解决Android4.4以上版本Uri转换 兼容Android 10
         *
         * @param context
         * @param imageUri
         */
        fun getPath(context: Context?, imageUri: Uri?): String? {
            if (context == null || imageUri == null) {
                return null
            }

            //4.4以下的版本
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
                return getRealFilePath(context, imageUri)
            }

            //大于4.4，小于10
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q && DocumentsContract.isDocumentUri(
                    context,
                    imageUri
                )
            ) {
                if (isExternalStorageDocument(imageUri)) {
                    val docId = DocumentsContract.getDocumentId(imageUri)
                    val split = docId.split(":").toTypedArray()
                    val type = split[0]
                    if ("primary".equals(type, ignoreCase = true)) {
                        return Environment.getExternalStorageDirectory().toString() + "/" + split[1]
                    }
                } else if (isDownloadsDocument(imageUri)) {
                    val id = DocumentsContract.getDocumentId(imageUri)
                    val contentUri = ContentUris.withAppendedId(
                        Uri.parse("content://downloads/public_downloads"),
                        java.lang.Long.valueOf(id)
                    )
                    return getDataColumn(context, contentUri, null, null)
                } else if (isMediaDocument(imageUri)) {
                    val docId = DocumentsContract.getDocumentId(imageUri)
                    val split = docId.split(":").toTypedArray()
                    val type = split[0]
                    var contentUri: Uri? = null
                    if ("image" == type) {
                        contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI
                    } else if ("video" == type) {
                        contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI
                    } else if ("audio" == type) {
                        contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
                    }
                    val selection = MediaStore.Images.Media._ID + "=?"
                    val selectionArgs = arrayOf(split[1])
                    return getDataColumn(context, contentUri, selection, selectionArgs)
                }
            }

            // MediaStore (and general)  大于等于10
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                return uriToFileApiQ(context, imageUri)
            } else if ("content".equals(imageUri.scheme, ignoreCase = true)) {
                // Return the remote address
                if (isGooglePhotosUri(imageUri)) {
                    return imageUri.lastPathSegment
                }
                return if (Build.VERSION.SDK_INT >= 24) {
                    getFilePathFromUri(context, imageUri) //content 类型
                } else {
                    getDataColumn(context, imageUri, null, null)
                }
            } else if ("file".equals(imageUri.scheme, ignoreCase = true)) {
                return imageUri.path
            }
            return null
        }

        private fun getRealFilePath(context: Context, uri: Uri?): String? {
            if (null == uri) {
                return null
            }
            val scheme = uri.scheme
            var data: String? = null
            if (scheme == null) {
                data = uri.path
            } else if (ContentResolver.SCHEME_FILE == scheme) {
                data = uri.path
            } else if (ContentResolver.SCHEME_CONTENT == scheme) {
                val projection = arrayOf(MediaStore.Images.ImageColumns.DATA)
                val cursor = context.contentResolver.query(uri, projection, null, null, null)
                if (null != cursor) {
                    if (cursor.moveToFirst()) {
                        val index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA)
                        if (index > -1) {
                            data = cursor.getString(index)
                        }
                    }
                    cursor.close()
                }
            }
            return data
        }


        private fun getDataColumn(context: Context,uri: Uri?, selection: String?,selectionArgs: Array<String>?
        ): String? {
            var cursor: Cursor? = null
            val column = MediaStore.Images.Media.DATA
            val projection = arrayOf(column)
            try {
                cursor =context.contentResolver.query(uri!!, projection, selection, selectionArgs, null)
                if (cursor != null && cursor.moveToFirst()) {
                    val index = cursor.getColumnIndexOrThrow(column)
                    return cursor.getString(index)
                }
            } finally {
                cursor?.close()
            }
            return null
        }

        /**
         * @param uri The Uri to check.
         * @return Whether the Uri authority is ExternalStorageProvider.
         */
        private fun isExternalStorageDocument(uri: Uri): Boolean {
            return "com.android.externalstorage.documents" == uri.authority
        }

        /**
         * @param uri The Uri to check.
         * @return Whether the Uri authority is DownloadsProvider.
         */
        private fun isDownloadsDocument(uri: Uri): Boolean {
            return "com.android.providers.downloads.documents" == uri.authority
        }

        /**
         * @param uri The Uri to check.
         * @return Whether the Uri authority is MediaProvider.
         */
        private fun isMediaDocument(uri: Uri): Boolean {
            return "com.android.providers.media.documents" == uri.authority
        }

        /**
         * @param uri The Uri to check.
         * @return Whether the Uri authority is Google Photos.
         */
        private fun isGooglePhotosUri(uri: Uri): Boolean {
            return "com.google.android.apps.photos.content" == uri.authority
        }



        /**
         * Android 10 以上适配 另一种写法
         * @param context
         * @param uri
         * @return
         */
        @SuppressLint("Range")
        private fun getFileFromContentUri(context: Context, uri: Uri?): String? {
            if (uri == null) {
                return null
            }
            val filePath: String
            val filePathColumn =arrayOf(MediaStore.DownloadColumns.DATA, MediaStore.DownloadColumns.DISPLAY_NAME)
            val contentResolver = context.contentResolver
            val cursor = contentResolver.query(
                uri, filePathColumn, null,
                null, null
            )
            if (cursor != null) {
                cursor.moveToFirst()
                try {
                    filePath = cursor.getString(cursor.getColumnIndex(filePathColumn[0]))
                    return filePath
                } catch (e: java.lang.Exception) {
                } finally {
                    cursor.close()
                }
            }
            return ""
        }

        /**
         * Android 10 以上适配
         * @param context
         * @param uri
         * @return
         */
        @SuppressLint("Range")
        private fun uriToFileApiQ(context: Context, uri: Uri): String? {
            var file: File? = null
            //android10以上转换
            if (uri.scheme == ContentResolver.SCHEME_FILE) {
                file = File(uri.path)
            } else if (uri.scheme == ContentResolver.SCHEME_CONTENT) {
                //把文件复制到沙盒目录
                val contentResolver = context.contentResolver
                val cursor = contentResolver.query(uri, null, null, null, null)
                if (cursor!!.moveToFirst()) {
                    val displayName =cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME))
                    try {
                        val `is` = contentResolver.openInputStream(uri)
                        val file1 =
                            File(context.externalCacheDir!!.absolutePath + "/" + System.currentTimeMillis())
                        if (!file1.exists()) {
                            file1.mkdir()
                        }
                        val cache = File(file1.path, displayName)
                        val fos = FileOutputStream(cache)
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                            FileUtils.copy(`is`!!, fos)
                        }
                        file = cache
                        fos.close()
                        `is`?.close()
                    } catch (e: IOException) {
                        e.printStackTrace()
                    }
                }
            }
            return file!!.absolutePath
        }

        private fun getFilePathFromUri(context: Context, uri: Uri): String? {
            val realFilePath = getRealFilePath(context, uri) //防止获取不到真实的地址，因此这里需要进行判断
            if (!TextUtils.isEmpty(realFilePath)) {
                return realFilePath
            }
            val filesDir = context.applicationContext.filesDir
            val fileName = getFileName(uri)
            if (!TextUtils.isEmpty(fileName)) {
                val copyFile1 = File(filesDir.toString() + File.separator + fileName)
                copyFile(context, uri, copyFile1)
                return copyFile1.absolutePath
            }
            return null
        }

        private fun getFileName(uri: Uri?): String? {
            if (uri == null) {
                return null
            }
            var fileName: String? = null
            val path = uri.path
            val cut = path!!.lastIndexOf('/')
            if (cut != -1) {
                fileName = path.substring(cut + 1)
            }
            return fileName
        }

        private fun copyFile(context: Context, srcUri: Uri, dstFile: File) {
            try {
                val inputStream = context.contentResolver.openInputStream(srcUri) ?: return
                val outputStream: OutputStream = FileOutputStream(dstFile)
                copyStream(inputStream, outputStream)
                inputStream.close()
                outputStream.close()
            } catch (e: java.lang.Exception) {
                e.printStackTrace()
            }
        }


        private fun copyStream(input: InputStream, output: OutputStream): Int {
            val BUFFER_SIZE = 1024 * 2
            val buffer = ByteArray(BUFFER_SIZE)
            val `in` = BufferedInputStream(input, BUFFER_SIZE)
            val out = BufferedOutputStream(output, BUFFER_SIZE)
            var count = 0
            var n = 0
            try {
                while (`in`.read(buffer, 0, BUFFER_SIZE).also { n = it } != -1) {
                    out.write(buffer, 0, n)
                    count += n
                }
                out.flush()
            } catch (e: java.lang.Exception) {
            } finally {
                try {
                    out.close()
                    `in`.close()
                } catch (e: java.lang.Exception) {
                }
            }
            return count
        }


        /**
         * 获取uri
         */
        fun getOutputMediaFileUri(context: Context): Uri? {
            var mediaFile: File? = null
            try {
                val mediaStorageDir = File(Environment.getExternalStorageDirectory().absolutePath)
                if (!mediaStorageDir.exists()) {
                    if (!mediaStorageDir.mkdirs()) {
                        return null
                    }
                }
                mediaFile = File(
                    mediaStorageDir.path
                            + File.separator
                            + "external.jpg"
                ) //注意这里需要和filepaths.xml中配置的一样
            } catch (e: java.lang.Exception) {
                e.printStackTrace()
            }
            return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // sdk >= 24  android7.0以上
                FileProvider.getUriForFile(
                    context,
                    context.applicationContext.packageName + ".fileprovider",  //与清单文件中android:authorities的值保持一致
                    (mediaFile)!!
                )
            } else {
                Uri.fromFile(mediaFile) //或者 Uri.isPaise("file://"+file.toString()
            }
        }

        fun getOutputMediaFileUrl():String?{
            val cameraPath: String
            try {
                val mediaStorageDir = File(Environment.getExternalStorageDirectory().absolutePath)
                if (!mediaStorageDir.exists()) {
                    if (!mediaStorageDir.mkdirs()) {
                        return null
                    }
                }
                var  mediaFile = File(
                    mediaStorageDir.path
                            + File.separator
                            + "external.jpg"
                )
                return if (mediaFile.exists()) {
                    cameraPath = mediaFile.path
                    cameraPath
                }else {
                    null
                }

            } catch (e: java.lang.Exception) {
                e.printStackTrace()
                return null
            }
        }



        /**
         * 预览文件
         *
         * @param context
         * @param path
         */
        fun openFile(context: Context, path: String) {
            try {
                val file: File = File(path)
                var uri: Uri? = null
                uri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //24 android7
                    FileProvider.getUriForFile(
                        context,
                        context.packageName.toString() + ".fileprovider",
                        file
                    )
                } else {
                    Uri.fromFile(file)
                }
                context.grantUriPermission(
                    context.packageName,
                    uri,
                    Intent.FLAG_GRANT_READ_URI_PERMISSION
                )
                val intent2 = Intent("android.intent.action.VIEW")
                intent2.addCategory("android.intent.category.DEFAULT")
                intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                intent2.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
                Log.d("sss", "opneFile: uri $uri")
                val type: String? = getMIMETypeString(file)
                intent2.setDataAndType(uri, type)
                context.startActivity(intent2)
            } catch (e: Exception) {
                Log.i("sss", "loadAccessorySuccess: error $e")
            }
        }

        fun getMIMETypeString(file: File): String? {
            var type: String? = "*/*"
            val strings = file.path.split("/").toTypedArray()
            val fName = strings[strings.size - 1]
            //获取后缀名前的分隔符"."在fName中的位置。
            var dotIndex = fName.lastIndexOf(".")
            if (dotIndex < 0) {
                return type
            }
            dotIndex++
            /* 获取文件的后缀名 */
            val end = fName.substring(dotIndex, fName.length).lowercase(Locale.getDefault())
            if (TextUtils.isEmpty(end)) return type
            //在MIME和文件类型的匹配表中找到对应的MIME类型。
            for (i in MIME_MapTable.indices) {
                if (end == MIME_MapTable[i][0]) type = MIME_MapTable[i][1]
            }
            return type
        }

        val MIME_MapTable = arrayOf(
            arrayOf("pbm", "image/x-portable-bitmap"),
            arrayOf("pcx", "image/x-pcx"),
            arrayOf("nbmp", "image/nbmp"),
            arrayOf("pda", "image/x-pda"),
            arrayOf("pgm", "image/x-portable-graymap"),
            arrayOf("pict", "image/x-pict"),
            arrayOf("png", "image/png"),
            arrayOf("pnm", "image/x-portable-anymap"),
            arrayOf("pnz", "image/png"),
            arrayOf("ppm", "image/x-portable-pixmap"),
            arrayOf("nokia-op-logo", "image/vnd.nok-oplogo-color"),
            arrayOf("qti", "image/x-quicktime"),
            arrayOf("qtif", "image/x-quicktime"),
            arrayOf("ras", "image/x-cmu-raster"),
            arrayOf("rf", "image/vnd.rn-realflash"),
            arrayOf("rp", "image/vnd.rn-realpix"),
            arrayOf("rgb", "image/x-rgb"),
            arrayOf("si9", "image/vnd.lgtwap.sis"),
            arrayOf("si7", "image/vnd.stiwap.sis"),
            arrayOf("svf", "image/vnd"),
            arrayOf("svg", "image/svg-xml"),
            arrayOf("svh", "image/svh"),
            arrayOf("si6", "image/si6"),
            arrayOf("tif", "image/tiff"),
            arrayOf("tiff", "image/tiff"),
            arrayOf("toy", "image/toy"),
            arrayOf("wbmp", "image/vnd.wap.wbmp"),
            arrayOf("wi", "image/wavelet"),
            arrayOf("wpng", "image/x-up-wpng"),
            arrayOf("xbm", "image/x-xbitmap"),
            arrayOf("xpm", "image/x-xpixmap"),
            arrayOf("xwd", "image/x-xwindowdump"),
            arrayOf("fh4", "image/x-freehand"),
            arrayOf("fh5", "image/x-freehand"),
            arrayOf("fhc", "image/x-freehand"),
            arrayOf("fif", "image/fif"),
            arrayOf("bmp", "image/bmp"),
            arrayOf("cal", "image/x-cals"),
            arrayOf("cod", "image/cis-cod"),
            arrayOf("fpx", "image/x-fpx"),
            arrayOf("dcx", "image/x-dcx"),
            arrayOf("eri", "image/x-eri"),
            arrayOf("gif", "image/gif"),
            arrayOf("ief", "image/ief"),
            arrayOf("ifm", "image/gif"),
            arrayOf("ifs", "image/ifs"),
            arrayOf("j2k", "image/j2k"),
            arrayOf("jpe", "image/jpeg"),
            arrayOf("jpeg", "image/jpeg"),
            arrayOf("jpg", "image/jpeg"),
            arrayOf("jpz", "image/jpeg"),
            arrayOf("mil", "image/x-cals"),

            arrayOf("3gp", "video/3gpp"),
            arrayOf("asf", "video/x-ms-asf"),
            arrayOf("asx", "video/x-ms-asf"),
            arrayOf("avi", "video/x-msvideo"),
            arrayOf("fvi", "video/isivideo"),
            arrayOf("lsf", "video/x-ms-asf"),
            arrayOf("lsx", "video/x-ms-asf"),
            arrayOf("m4u", "video/vnd.mpegurl"),
            arrayOf("m4v", "video/x-m4v"),
            arrayOf("pvx", "video/x-pv-pvx"),
            arrayOf("qt", "video/quicktime"),
            arrayOf("rv", "video/vnd.rn-realvideo"),
            arrayOf("viv", "video/vivo"),
            arrayOf("vivo", "video/vivo"),
            arrayOf("vdo", "video/vdo"),
            arrayOf("wm", "video/x-ms-wm"),
            arrayOf("wmx", "video/x-ms-wmx"),
            arrayOf("wv", "video/wavelet"),
            arrayOf("wvx", "video/x-ms-wvx"),
            arrayOf("mov", "video/quicktime"),
            arrayOf("movie", "video/x-sgi-movie"),
            arrayOf("mp4", "video/mp4"),
            arrayOf("mng", "video/x-mng"),
            arrayOf("mpe", "video/mpeg"),
            arrayOf("mpeg", "video/mpeg"),
            arrayOf("mpg video/mpeg"),
            arrayOf("mpg4", "video/mp4"),

            arrayOf("aif", "audio/x-aiff"),
            arrayOf("aifc", "audio/x-aiff"),
            arrayOf("aiff", "audio/x-aiff"),
            arrayOf("als", "audio/X-Alpha5"),
            arrayOf("au", "audio/basic"),
            arrayOf("es", "audio/echospeech"),
            arrayOf("esl", "audio/echospeech"),
            arrayOf("awb", "audio/amr-wb"),
            arrayOf("imy", "audio/melody"),
            arrayOf("it", "audio/x-mod"),
            arrayOf("itz", "audio/x-mod"),
            arrayOf("tsi", "audio/tsplayer"),
            arrayOf("ult", "audio/x-mod"),
            arrayOf("vib", "audio/vib"),
            arrayOf("vox", "audio/voxware"),
            arrayOf("vqe", "audio/x-twinvq-plugin"),
            arrayOf("vqf", "audio/x-twinvq"),
            arrayOf("vql", "audio/x-twinvq"),
            arrayOf("wav", "audio/x-wav"),
            arrayOf("wax", "audio/x-ms-wax"),
            arrayOf("wmv", "audio/x-ms-wmv"),
            arrayOf("wma", "audio/x-ms-wma"),
            arrayOf("xmz", "audio/x-mod"),
            arrayOf("m15", "audio/x-mod"),
            arrayOf("m3u", "audio/x-mpegurl"),
            arrayOf("m3url", "audio/x-mpegurl"),
            arrayOf("m4a", "audio/mp4a-latm"),
            arrayOf("m4b", "audio/mp4a-latm"),
            arrayOf("m4p", "audio/mp4a-latm"),
            arrayOf("ma1", "audio/ma1"),
            arrayOf("ma2", "audio/ma2"),
            arrayOf("ma3", "audio/ma3"),
            arrayOf("ma5", "audio/ma5"),
            arrayOf("mdz", "audio/x-mod"),
            arrayOf("mid", "audio/midi"),
            arrayOf("midi", "audio/midi"),
            arrayOf("mio", "audio/x-mio"),
            arrayOf("mod", "audio/x-mod"),
            arrayOf("mp2", "audio/x-mpeg"),
            arrayOf("mp3", "audio/x-mpeg"),
            arrayOf("mpga", "audio/mpeg"),
            arrayOf("ogg", "audio/ogg"),
            arrayOf("nsnd", "audio/nsnd"),
            arrayOf("pae", "audio/x-epac"),
            arrayOf("pac", "audio/x-pac"),
            arrayOf("qcp", "audio/vnd.qcelp"),
            arrayOf("ra", "audio/x-pn-realaudio"),
            arrayOf("ram", "audio/x-pn-realaudio"),
            arrayOf("rm", "audio/x-pn-realaudio"),
            arrayOf("rmf", "audio/x-rmf"),
            arrayOf("rmm", "audio/x-pn-realaudio"),
            arrayOf("rmvb", "audio/x-pn-realaudio"),
            arrayOf("rpm", "audio/x-pn-realaudio-plugin"),
            arrayOf("s3m", "audio/x-mod"),
            arrayOf("s3z", "audio/x-mod"),
            arrayOf("stm", "audio/x-mod"),
            arrayOf("smz", "audio/x-smd"),
            arrayOf("snd", "audio/basic"),
            arrayOf("smd", "audio/x-smd"),
            arrayOf("xm", "audio/x-mod"),

            arrayOf("c", "text/plain"),
            arrayOf("asc", "text/plain"),
            arrayOf("conf", "text/plain"),
            arrayOf("cpp", "text/plain"),
            arrayOf("css", "text/css"),
            arrayOf("dhtml", "text/html"),
            arrayOf("etx", "text/x-setext"),
            arrayOf("h", "text/plain"),
            arrayOf("hdm", "text/x-hdml"),
            arrayOf("hdml", "text/x-hdml"),
            arrayOf("htm", "text/html"),
            arrayOf("html", "text/html"),
            arrayOf("hts", "text/html"),
            arrayOf("jad", "text/vnd.sun.j2me.app-descriptor"),
            arrayOf("java", "text/plain"),
            arrayOf("log", "text/plain"),
            arrayOf("mel", "text/x-vmel"),
            arrayOf("mrl", "text/x-mrml"),
            arrayOf("prop", "text/plain"),
            arrayOf("r3t", "text/vnd.rn-realtext3d"),
            arrayOf("sgm", "text/x-sgml"),
            arrayOf("rc", "text/plain"),
            arrayOf("rtx", "text/richtext"),
            arrayOf("rt", "text/vnd.rn-realtext"),
            arrayOf("sgml", "text/x-sgml"),
            arrayOf("spc", "text/x-speech"),
            arrayOf("txt", "text/plain"),
            arrayOf("tsv", "text/tab-separated-values"),
            arrayOf("tsv", "text/tab-separated-values"),
            arrayOf("talk", "text/x-speech"),
            arrayOf("vcf", "text/x-vcard"),
            arrayOf("wml", "text/vnd.wap.wml"),
            arrayOf("wmls", "text/vnd.wap.wmlscript"),
            arrayOf("wmlscript", "text/vnd.wap.wmlscript"),
            arrayOf("ws", "text/vnd.wap.wmlscript"),
            arrayOf("xml", "text/xml"),
            arrayOf("xsit", "text/xml"),
            arrayOf("xsl", "text/xml"),
            arrayOf("xul", "text/xul"),

            arrayOf("apk", "application/vnd.android.package-archive"),

            arrayOf("aab", "application/x-authoware-bin"),
            arrayOf("aam", "application/x-authoware-map"),
            arrayOf("aas", "application/x-authoware-seg"),
            arrayOf("ai", "application/postscript"),
            arrayOf("amc", "application/x-mpeg"),
            arrayOf("ani", "application/octet-stream"),
            arrayOf("asd", "application/astound"),
            arrayOf("asn", "application/astound"),
            arrayOf("asp", "application/x-asap"),
            arrayOf("avb", "application/octet-stream"),
            arrayOf("bcpio", "application/x-bcpio"),
            arrayOf("bin", "application/octet-stream"),
            arrayOf("bld", "application/bld"),
            arrayOf("bld2", "application/bld2"),
            arrayOf("bpk", "application/octet-stream"),
            arrayOf("bz2", "application/x-bzip2"),
            arrayOf("ccn", "application/x-cnc"),
            arrayOf("cco", "application/x-cocoa"),
            arrayOf("cdf", "application/x-netcdf"),
            arrayOf("chat", "application/x-chat"),
            arrayOf("class", "application/octet-stream"),
            arrayOf("clp", "application/x-msclip"),
            arrayOf("cmx", "application/x-cmx"),
            arrayOf("co", "application/x-cult3d-object"),
            arrayOf("cpio", "application/x-cpio"),
            arrayOf("cpt", "application/mac-compactpro"),
            arrayOf("crd", "application/x-mscardfile"),
            arrayOf("csh", "application/x-csh"),
            arrayOf("cur", "application/octet-stream"),
            arrayOf("dcr", "application/x-director"),
            arrayOf("dir", "application/x-director"),
            arrayOf("dll", "application/octet-stream"),
            arrayOf("dmg", "application/octet-stream"),
            arrayOf("dms", "application/octet-stream"),
            arrayOf("doc", "application/msword"),
            arrayOf(
                "docx",
                "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
            ),
            arrayOf("dot", "application/x-dot"),
            arrayOf("dvi", "application/x-dvi"),
            arrayOf("dwg", "application/x-autocad"),
            arrayOf("dxf", "application/x-autocad"),
            arrayOf("dxr", "application/x-director"),
            arrayOf("ebk", "application/x-expandedbook"),
            arrayOf("eps", "application/postscript"),
            arrayOf("evy", "application/x-envoy"),
            arrayOf("exe", "application/octet-stream"),
            arrayOf("etc", "application/x-earthtime"),
            arrayOf("fm", "application/x-maker"),
            arrayOf("gps", "application/x-gps"),
            arrayOf("gtar", "application/x-gtar"),
            arrayOf("gz", "application/x-gzip"),
            arrayOf("gca", "application/x-gca-compressed"),
            arrayOf("hdf", "application/x-hdf"),
            arrayOf("hlp", "application/winhlp"),
            arrayOf("hqx", "application/mac-binhex40"),
            arrayOf("ico", "application/octet-stream"),
            arrayOf("ins", "application/x-NET-Install"),
            arrayOf("ips", "application/x-ipscript"),
            arrayOf("ipx", "application/x-ipix"),
            arrayOf("jam", "application/x-jam"),
            arrayOf("jar", "application/java-archive"),
            arrayOf("jnlp", "application/x-java-jnlp-file"),
            arrayOf("latex", "application/x-latex"),
            arrayOf("lcc", "application/fastman"),
            arrayOf("lcl", "application/x-digitalloca"),
            arrayOf("lcr", "application/x-digitalloca"),
            arrayOf("lgh", "application/lgh"),
            arrayOf("lha", "application/octet-stream"),
            arrayOf("js", "application/x-javascript"),
            arrayOf("jwc", "application/jwc"),
            arrayOf("kjx", "application/x-kjx"),
            arrayOf("lzh", "application/x-lzh"),
            arrayOf("m13", "application/x-msmediaview"),
            arrayOf("m14", "application/x-msmediaview"),
            arrayOf("man", "application/x-troff-man"),
            arrayOf("mbd", "application/mbedlet"),
            arrayOf("mct", "application/x-mascot"),
            arrayOf("mdb", "application/x-msaccess"),
            arrayOf("me", "application/x-troff-me"),
            arrayOf("mi", "application/x-mif"),
            arrayOf("mif", "application/x-mif"),
            arrayOf("mmf", "application/x-skt-lbs"),
            arrayOf("mny", "application/x-msmoney"),
            arrayOf("moc", "application/x-mocha"),
            arrayOf("mocha", "application/x-mocha"),
            arrayOf("mpn", "application/vnd.mophun.application"),
            arrayOf("mpc", "application/vnd.mpohun.certificate"),
            arrayOf("mof", "application/x-yumekara"),
            arrayOf("mpp", "application/vnd.ms-project"),
            arrayOf("mps", "application/x-mapserver"),
            arrayOf("mrm", "application/x-mrm"),
            arrayOf("ms", "application/x-troff-ms"),
            arrayOf("msg", "application/vnd.ms-outlook"),
            arrayOf("mts", "application/metastream"),
            arrayOf("mtx", "application/metastream"),
            arrayOf("mtz", "application/metastream"),
            arrayOf("mzv", "application/metastream"),
            arrayOf("nar", "application/zip"),
            arrayOf("nc", "application/x-netcdf"),
            arrayOf("ndwn", "application/ndwn"),
            arrayOf("nif", "application/x-nif"),
            arrayOf("nmz", "application/x-scream"),
            arrayOf("npx", "application/x-netfpx"),
            arrayOf("nva", "application/x-neva1"),
            arrayOf("oda", "application/oda"),
            arrayOf("oom", "application/x-AtlasMate-Plugin"),
            arrayOf("pan", "application/x-pan"),
            arrayOf("pdf", "application/pdf"),
            arrayOf("pfr", "application/font-tdpfr"),
            arrayOf("pm", "application/x-perl"),
            arrayOf("pmd", "application/x-pmd"),
            arrayOf("pot", "application/vnd.ms-powerpoint"),
            arrayOf("pps", "application/vnd.ms-powerpoint"),
            arrayOf("ppt", "application/vnd.ms-powerpoint"),
            arrayOf(
                "pptx",
                "application/vnd.openxmlformats-officedocument.presentationml.presentation"
            ),
            arrayOf("pqf", "application/x-cprplayer"),
            arrayOf("pqi", "application/cprplayer"),
            arrayOf("proxy", "application/x-ns-proxy-autoconfig"),
            arrayOf("ps", "application/postscript"),
            arrayOf("ptlk", "application/listenup"),
            arrayOf("pub", "application/x-mspublisher"),
            arrayOf("prc", "application/x-prc"),
            arrayOf("rar", "application/x-rar-compressed"),
            arrayOf("rdf", "application/rdf+xml"),
            arrayOf("rlf", "application/x-richlink"),
            arrayOf("rnx", "application/vnd.rn-realplayer"),
            arrayOf("roff", "application/x-troff"),
            arrayOf("rtf", "application/rtf"),
            arrayOf("rtg", "application/metastream"),
            arrayOf("rwc", "application/x-rogerwilco"),
            arrayOf("sca", "application/x-supercard"),
            arrayOf("scd", "application/x-msschedule"),
            arrayOf("sdf", "application/e-score"),
            arrayOf("sea", "application/x-stuffit"),
            arrayOf("sh", "application/x-sh"),
            arrayOf("shw", "application/presentations"),
            arrayOf("shar", "application/x-shar"),
            arrayOf("sis", "application/vnd.symbian.install"),
            arrayOf("sit", "application/x-stuffit"),
            arrayOf("skd", "application/x-Koan"),
            arrayOf("skm", "application/x-Koan"),
            arrayOf("skp", "application/x-Koan"),
            arrayOf("skt", "application/x-Koan"),
            arrayOf("slc", "application/x-salsa"),
            arrayOf("smi", "application/smil"),
            arrayOf("smil", "application/smil"),
            arrayOf("smp", "application/studiom"),
            arrayOf("spl", "application/futuresplash"),
            arrayOf("spr", "application/x-sprite"),
            arrayOf("sprite", "application/x-sprite"),
            arrayOf("spt", "application/x-spt"),
            arrayOf("src", "application/x-wais-source"),
            arrayOf("stk", "application/hyperstudio"),
            arrayOf("sv4cpio", "application/x-sv4cpio"),
            arrayOf("sv4crc", "application/x-sv4crc"),
            arrayOf("swf", "application/x-shockwave-flash"),
            arrayOf("swfl", "application/x-shockwave-flash"),
            arrayOf("t", "application/x-troff"),
            arrayOf("tad", "application/octet-stream"),
            arrayOf("tar", "application/x-tar"),
            arrayOf("taz", "application/x-tar"),
            arrayOf("tbp", "application/x-timbuktu"),
            arrayOf("tbt", "application/x-timbuktu"),
            arrayOf("tcl", "application/x-tcl"),
            arrayOf("tex", "application/x-tex"),
            arrayOf("texi", "application/x-texinfo"),
            arrayOf("texinfo", "application/x-texinfo"),
            arrayOf("tgz", "application/x-tar"),
            arrayOf("thm", "application/vnd.eri.thm"),
            arrayOf("tki", "application/x-tkined"),
            arrayOf("tkined", "application/x-tkined"),
            arrayOf("toc", "application/toc"),
            arrayOf("tr", "application/x-troff"),
            arrayOf("trm", "application/x-msterminal"),
            arrayOf("tsp", "application/dsptype"),
            arrayOf("ttf", "application/octet-stream"),
            arrayOf("ttz", "application/t-time"),
            arrayOf("ustar", "application/x-ustar"),
            arrayOf("uu", "application/x-uuencode"),
            arrayOf("uue", "application/x-uuencode"),
            arrayOf("vcd", "application/x-cdlink"),
            arrayOf("vmd", "application/vocaltec-media-desc"),
            arrayOf("vmf", "application/vocaltec-media-file"),
            arrayOf("vmi", "application/x-dreamcast-vms-info"),
            arrayOf("vms", "application/x-dreamcast-vms"),
            arrayOf("wis", "application/x-InstallShield"),
            arrayOf("wmd", "application/x-ms-wmd"),
            arrayOf("wmf", "application/x-msmetafile"),
            arrayOf("wmlc", "application/vnd.wap.wmlc"),
            arrayOf("wmlsc", "application/vnd.wap.wmlscriptc"),
            arrayOf("wps", "application/vnd.ms-works"),
            arrayOf("wmz", "application/x-ms-wmz"),
            arrayOf("wri", "application/x-mswrite"),
            arrayOf("web", "application/vnd.xara"),
            arrayOf("wsc", "application/vnd.wap.wmlscriptc"),
            arrayOf("wxl", "application/x-wxl"),
            arrayOf("x-gzip", "application/x-gzip"),
            arrayOf("xar", "application/vnd.xara"),
            arrayOf("xdm", "application/x-xdma"),
            arrayOf("xdma", "application/x-xdma"),
            arrayOf("xdw", "application/vnd.fujixerox.docuworks"),
            arrayOf("xht", "application/xhtml+xml"),
            arrayOf("xhtm", "application/xhtml+xml"),
            arrayOf("xhtml", "application/xhtml+xml"),
            arrayOf("xla", "application/vnd.ms-excel"),
            arrayOf("xlc", "application/vnd.ms-excel"),
            arrayOf("xll", "application/x-excel"),
            arrayOf("xlm", "application/vnd.ms-excel"),
            arrayOf("xls", "application/vnd.ms-excel"),
            arrayOf("xlt", "application/vnd.ms-excel"),
            arrayOf("xlw", "application/vnd.ms-excel"),
            arrayOf("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
            arrayOf("xpi", "application/x-xpinstall"),
            arrayOf("yz1", "application/x-yz1"),
            arrayOf("z", "application/x-compress"),
            arrayOf("zac", "application/x-zaurus-zac"),
            arrayOf("zip", "application/zip"),

            arrayOf("gau", "chemical/x-gaussian-input"),
            arrayOf("csm", "chemical/x-csml"),
            arrayOf("csml", "chemical/x-csml"),
            arrayOf("emb", "chemical/x-embl-dl-nucleotide"),
            arrayOf("embl", "chemical/x-embl-dl-nucleotide"),
            arrayOf("mol", "chemical/x-mdl-molfile"),
            arrayOf("pdb", "chemical/x-pdb"),
            arrayOf("xyz", "chemical/x-pdb"),
            arrayOf("mop", "chemical/x-mopac-input"),

            arrayOf("dcm", "x-lml/x-evm"),
            arrayOf("evm", "x-lml/x-evm"),
            arrayOf("gdb", "x-lml/x-gdb"),
            arrayOf("lak", "x-lml/x-lak"),
            arrayOf("lml", "x-lml/x-lml"),
            arrayOf("lmlpack", "x-lml/x-lmlpack"),
            arrayOf("ndb", "x-lml/x-ndb"),
            arrayOf("rte", "x-lml/x-gps"),
            arrayOf("wpt", "x-lml/x-gps"),
            arrayOf("trk", "x-lml/x-gps"),

            arrayOf("svr", "x-world/x-svr"),
            arrayOf("ivr", "i-world/i-vrml"),
            arrayOf("vre", "x-world/x-vream"),
            arrayOf("vrml", "x-world/x-vrml"),
            arrayOf("vrt", "x-world/x-vrt"),
            arrayOf("vrw", "x-world/x-vream"),
            arrayOf("vts", "workbook/formulaone"),
            arrayOf("wrl", "x-world/x-vrml"),
            arrayOf("wrz", "x-world/x-vrml"),

            arrayOf("dwf", "drawing/x-dwf"),
            arrayOf("ice", "x-conference/x-cooltalk"),
            arrayOf("map", "magnus-internal/imagemap"),
            arrayOf("shtml", "magnus-internal/parsed-html"),
            arrayOf("cgi", "magnus-internal/cgi"),

            arrayOf("", "*/*")
        )

    }

}